package com.liwc.controller.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.liwc.constant.StatusCode;
import com.liwc.message.ResponseMessage;
import com.liwc.model.Notepad;
import com.liwc.model.page.EasyuiPageModel;
import com.liwc.service.NotepadService;

/**
 * 
 * 模块：基于RBAC的基础权限框架demo
 * <br/>描述：记事本rest接口
 * @author liwc
 * @date 2018年7月1日 下午12:01:13
 * @类名 NotepadController
 */
@RestController
@RequestMapping(value="rest/business/notepad")
public class NotepadRestController {

	private static Logger log = LoggerFactory.getLogger(NotepadRestController.class);
	

	// 账户类型service
	@Autowired
	private NotepadService service;
	
	
	/**
	 * 查询列表
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "list")
	public EasyuiPageModel list(Notepad dto) {
		PageInfo<Notepad> pi = service.findAll(dto);
		log.debug("----->总数量："+ pi.getTotal() +",分页数量："+ pi.getList().size());
		return new EasyuiPageModel(pi.getTotal(), pi.getList());
	}
	
	
	
	
	@RequestMapping(value = "{id}")
	public ResponseMessage info(@PathVariable("id") Integer id) {
		Notepad entity = service.findById(id);
		ResponseMessage message = new ResponseMessage(StatusCode.OK, "ok", entity);
		return message;
		
	}
	
	
	
	@RequestMapping(value = "save", method=RequestMethod.POST)
	public ResponseMessage save(Notepad record) {
		return service.save(record);
	}
	
	
	
	@RequestMapping(value= "/delete/{id}", method=RequestMethod.POST)
	public ResponseMessage delete(@PathVariable("id") Integer id){
		return service.deleteById(id);
	}
	
	
	
}
